home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / rpg / crossfir.92 / crossfir / crossfire-0.92.5 / doc / spoiler / makeps < prev    next >
Text File  |  1996-07-24  |  5KB  |  154 lines

  1.  
  2. # makeps - make Postscript-files of the archetypes listed in text file whose
  3. # filename is passed in 'input'
  4. # Variables passed in:
  5. #   archdir - root of crossfire-src, with a trailing slash
  6. #   libdir  - where archetypes etc. is found
  7.  
  8. BEGIN {
  9.     # Set colour to 1 if you want colour postscript.
  10.     colour = 0;
  11.  
  12.     if (colour) {
  13.       xpm2ps = "xpmtoppm | pnmdepth 255 | pnmtops"
  14.       ppm2ps = "pnmdepth 255 | pnmtops"
  15.     } else {
  16.       xpm2ps = "xpmtoppm | pnmdepth 255 | ppmtopgm | pnmtops"
  17.         ppm2ps = "pnmdepth 255 | ppmtopgm | pnmtops"
  18.     }
  19.  
  20.     bmaps = libdir "/bmaps";
  21.     bmappaths = libdir "/bmaps.paths";
  22.  
  23.     while ((getline < bmappaths) == 1)
  24.     if ($1 != "#")
  25.         bmappath[$1] = $2;
  26.     close(bmappaths)
  27.  
  28.     while ((getline < bmaps) == 1)
  29.         if (("\\" $1) in bmappath)
  30.             bmap[$2] = bmappath["\\" $1];
  31.     close(bmaps);
  32.  
  33.  
  34.     # An array listing which archetypes files need fixing, the value
  35.     # is the file where it is used. There must be at least one character
  36.     # between the ~~spec~~'s.
  37.  
  38.     oldFS=FS; FS="~~"; oldOFS=OFS; OFS="";
  39.     while ((getline < input) == 1) {
  40.     if (NF > 1) {
  41.             work_todo = 1;
  42.         for (i = 2; i < NF; i += 2)
  43.         if ($i != "")
  44.                 makeps[$i] = $1;
  45.     }
  46.     }
  47.     close(input);
  48.     FS=oldFS; OFS=oldOFS;
  49.  
  50.     if (!work_todo)
  51.     exit;
  52.  
  53.     # An array to reduce the size of the bitmap exponentially.
  54.     # A 4x8 bitmap will be reduced to 60% of its full size.
  55.     size_mul[1] = 1;
  56.     for (i = 2; i <= 12; i++)        # Max input is 12x12, a *large* bitmap ;-)
  57.         size_mul[i] = size_mul[i-1] * 0.9;
  58.  
  59. }
  60.  
  61. $1 == "Object"    {
  62.     if (interesting) {
  63.         faces[x,y] = face;
  64.         if (!More && makeps[obj] != 1)
  65.             makeps[obj] = assemble();
  66.     }
  67.  
  68.     # Get ready for next archetype
  69.     if (!More) {
  70.         xmin = xmax = ymin = ymax = 0;
  71.     obj = $2;
  72.     interesting = obj in makeps;
  73.     }
  74.     x = y = 0;
  75.     More = 0;
  76. }
  77.  
  78. $1 == "face"    { face = $2 }
  79. $1 == "x"       { x = $2; if (x > xmax) xmax = x; else if (x < xmin) xmin = x; }
  80. $1 == "y"       { y = $2; if (y > ymax) ymax = y; else if (y < ymin) ymin = y; }
  81. $1 == "More"    { More = 1; }
  82. $1 == "msg"    { do { getline } while ($1 != "endmsg"); }
  83.  
  84. END {
  85.     # Remember to check the last archetype also...
  86.     if (interesting) {
  87.         faces[x,y] = face;
  88.         if (makeps[obj] != 1)
  89.             makeps[obj] = assemble();
  90.     }
  91.  
  92.     system("rm -f work.pbm tmp.pbm");    # clean up a little
  93.  
  94.     # We've created a number of Postscript-files - now we need to
  95.     # patch the filenames and sizes into the TeX-files.
  96.  
  97.     FS="~~"; OFS="";
  98.     while ((getline < input) == 1) {
  99.         if (NF > 1) {
  100.         for (i = 2; i <= NF; i += 2)
  101.             if ($i in makeps)
  102.             $i = makeps[$i];
  103.         }
  104.         print;
  105.     }
  106.     close(input);
  107. }
  108.  
  109. function assemble(   w, h, ppm, buff, i, j, bmap_file, ps_file) {
  110.     bmap_file = archdir bmap[faces[0,0]] ".xpm";
  111.     ps_file =  faces[0,0] ".ps";
  112.     gsub(/[_ ]/, "-", ps_file);
  113.  
  114.     w = xmax - xmin + 1; h = ymax - ymin + 1;
  115.     if ((getline buff < ps_file) != -1)
  116.         close (ps_file);
  117.     else {
  118.         if (w == 1 && h == 1) {
  119.             system(sprintf("sed 's/[Nn]one/white/g' < %s | " xpm2ps " > %s",
  120.                            bmap_file, ps_file));
  121.         } else {
  122.             ppm = sprintf("%dx%d.ppm", w, h);
  123.         print ppm >>"/dev/stderr";
  124.             if ((getline buff < ppm) != -1)
  125.                 close(ppm);
  126.             else {
  127.         printf("pnmscale -xsc %d -ysc %d < empty.pbm | pgmtoppm white > %s\n", w, h, ppm) >>"/dev/stderr";
  128.                 system(sprintf("pnmscale -xsc %d -ysc %d < empty.pbm | pgmtoppm white > %s",
  129.                         w, h, ppm));
  130.  
  131.         }
  132.  
  133.             system("cp " ppm " work.ppm"); ppm = "work.ppm";
  134.  
  135.             for (i = xmin; i <= xmax; i++)
  136.                 for (j = ymin; j <= ymax; j++) {
  137.             print "Processing " bmap[faces[i,j]] >> "/dev/stderr";
  138.                     system(sprintf("sed 's/[Nn]one/white/g' < %s | xpmtoppm > tmp.ppm; pnmpaste tmp.ppm %d %d %s > tmp2.ppm; mv tmp2.ppm %s",
  139.                                    archdir bmap[faces[i,j]] ".xpm",
  140.                                    (i - xmin) * 24, (j - ymin) * 24, ppm, ppm));
  141.         }
  142.  
  143.             system(sprintf("cat %s | " ppm2ps " > %s", ppm, ps_file));
  144.         }
  145.     }
  146.     mul = size_mul[int(sqrt(w * h))] * size;
  147.     ps = sprintf("\\psfig{figure=" ps_file ",width=%0.2fcm,height=%0.2fcm,rwidth=%0.2fcm}",
  148.              w * mul, h * mul, w * mul - 0.15);
  149.     if (h == 1)
  150.     return ps;
  151.     else
  152.         return sprintf("\\raisebox{-%0.2fcm}{%s}", (h-1) * mul, ps);
  153. }
  154.